/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package converter.text2PEF;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;
import org.brailleblaster.*;
import org.brailleblaster.louisutdml.*;
import org.liblouis.liblouisutdml;
import constants.Constants;
/**
 *
 * @author CSE
 */
public class Text2PEFConverter {
  public String text2PEF(String name) {
    Runtime run = Runtime.getRuntime(); 
    String txtDir=null;
    String pefDir=null;
    String slash=null;
    String exe=null;
    String brailleUtilsPath=null;
    try{
    Properties prop = new Properties();
    
    InputStream is = new FileInputStream("application.properties");

    prop.load(is);

    txtDir=prop.getProperty(Constants.TEXT_FILE_LOC);
    pefDir=prop.getProperty(Constants.PEF_FILE_LOC);
    exe=prop.getProperty(Constants.JAVA_EXE);
    brailleUtilsPath=prop.getProperty(Constants.BRAILLEUTILS_PATH);
    
    }
    catch(Exception ex){
        ex.printStackTrace();
    }
    
try 
{    slash=Constants.PATH_SEPERATOR;
     String fileName=name+".txt";
     String txtFile=txtDir+slash+fileName;
     String pefFile=pefDir+slash+fileName+Constants.PEF;
     //need to set duplex property based on what user sending
    
     ProcessBuilder pb1=new ProcessBuilder(exe, Constants.JAR, brailleUtilsPath,Constants.TEXT2PEF,txtFile,pefFile,"-duplex=false");
     Process p = pb1.start();
    // ProcessBuilder pb2=new ProcessBuilder(exe, Constants.JAR, brailleUtilsPath,Constants.EMBOSS,pefFile);
    // pb2.start();
     File f=new File(pefFile);
     if(f.exists()){
         return pefFile;
     }
     return null;
    
    }
catch(Exception E) 
{
     E.printStackTrace();
     System.out.println(E.getMessage()); 
     return null;
}
}

    
}
